#include<iostream>
#include<vector>
using namespace std;
const int N=11;
bool arr[N];
vector<int>path;
void dfs(int n)
{
	if(path.size()==(size_t)n)
	{
		for(auto&e:path)
		{
			printf("%5d",e);
		}
		cout<<endl;
		return;
	}
	for(int i=1;i<=n;i++)
	{
		if(arr[i]) continue;
		path.push_back(i);
		arr[i]=true;
		dfs(n);
		path.pop_back();
		arr[i]=false;
	}
}
int main()
{
	int n;cin>>n;
	dfs(n);
}